import pygame, sys, math

from Block import Block

class Effect(pygame.sprite.Sprite):
	def __init__(self, images, pos = (0,0), blocksize = [50,50]):
		pygame.sprite.Sprite.__init__(self, self.containers)
		self.LightImages = [pygame.image.load("rsc/effects/elight.png"),
							pygame.image.load("rsc/effects/elight1.png"),
							pygame.image.load("rsc/effects/elight2.png"),
							pygame.image.load("rsc/effects/elight3.png")]
		self.LightImages = [pygame.transform.scale(self.LightImages[0], blocksize)]
		self.images = self.LightImages
		self.frame = 0
		self.maxFrame = len(self.images) - 1
		self.waitCount = 0
		self.waitCountMax = 1
		self.image = self.images[self.frame]
		self.rect = self.image.get_rect()
		self.realx = pos[0]
		self.realy = pos[1]
		self.x = pos[0]
		self.y = pos[1]
		self.place(pos)
		self.speedx = 0
		self.speedy = 0
		self.scrollingx = False
		self.scrollingy = False
	
	def animate(self):
		if self.waitCount < self.waitCountMax:
			self.waitCount += 1
		else:
			self.waitCount = 0
			if self.frame < self.maxFrame:
				self.frame += 1
			else:
				self.frame = 0
			self.image = self.images[self.frame]
		
	def place(self, pos):
		self.rect.center = pos
		
	def fixLocation(self, x, y):
		print x, y
		self.x += x
		self.y += y
		
	def update(*args):
		self = args[0]
		self.speedx = args[2]
		self.speedy = args[3]
		self.scrollingx = args[4]
		self.scrollingy = args[5]
		self.move()
		
	def move(self):
		if self.scrollingx:
			self.x -= self.speedx
		if self.scrollingy:
			self.y -= self.speedy
			
		self.rect.center = (round(self.x), round(self.y))